package com.tricky.demo.rabbit.handler;

import cn.hutool.json.JSONUtil;
import com.tricky.demo.rabbit.msg.DemoDataMsg;
import com.tricky.demo.rabbit.msg.DemoNumberMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


@Component
@RabbitListener(queues = "na_demo")
public class DemoMessageHandler {
	private static Logger logger = LoggerFactory.getLogger(DemoMessageHandler.class);


	@RabbitHandler
	public void handle(String data) {
		logger.info(String.format("收到的消息为:%s", data));
	}


	@RabbitHandler
	public void handle(DemoDataMsg data) {
		logger.info(String.format("收到的消息为:%s %s", data.getClass().getName(), JSONUtil.toJsonStr(data)));
	}

	@RabbitHandler
	public void handle(DemoNumberMsg data) {
		logger.info(String.format("收到的消息为:%s %s", data.getClass().getName(), JSONUtil.toJsonStr(data)));
	}
}
